package org.example.admin.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.example.admin.entity.Dish;
import org.example.admin.mapper.DishMapper;
import org.example.admin.service.DishService;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DishServiceImpl implements DishService {

    @Resource
    private DishMapper dishMapper;

    @Override
    public Dish selectById(Long dishId) {
        return dishMapper.selectById(dishId);
    }

    @Override
    public List<Dish> selectDish() {
        return dishMapper.selectDish();
    }

    @Override
    public List<Dish> selectByStoreId(Long storeId) {return dishMapper.selectByStoreId(storeId);}

    public PageInfo<Dish> searchDishByName(
            Integer pageNum, Integer pageSize,
            String keyword, Integer storeId) {
        // 1. 启动分页
        PageHelper.startPage(pageNum, pageSize);

        // 2. 执行查询（PageHelper会自动拦截并分页）
        List<Dish> dishes = dishMapper.selectDishByName(keyword, storeId);

        // 3. 封装分页结果
        return new PageInfo<>(dishes);
    }

    @Override
    public int updateDish(Dish dish) {
        return dishMapper.updateDish(dish);
    }

    @Override
    public int addDish(Dish dish) {
        return dishMapper.addDish(dish);
    }

    @Override
    public int deleteDish(Long dishId) {
        return dishMapper.deleteDish(dishId);
    }
}
